From: emellor@leeni.uk.xensource.com Date: Sun, 7 May 2006 12:34:45 +0000 (+0100) Subject: Abstract block-attach and block-detach calls, and add to that the correct X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~16108^2~8 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/success//%22http:/www.example.com/cgi/success/?a=commitdiff_plain;h=aed92ee453e344e1a45467b526ef0dac6d5b862f;p=xen.git Abstract block-attach and block-detach calls, and add to that the correct polling waiting for the device to connect and disconnect. Signed-off-by: Ewan Mellor --- diff --git a/tools/xm-test/lib/XmTestLib/block_utils.py b/tools/xm-test/lib/XmTestLib/block_utils.py new file mode 100644 index 0000000000..38c5d20d5f --- /dev/null +++ b/tools/xm-test/lib/XmTestLib/block_utils.py @@ -0,0 +1,53 @@ +#!/usr/bin/python + +# Copyright (c) 2006 XenSource Inc. +# Author: Ewan Mellor + +import time + +from XmTestLib import * + +import xen.util.blkif + + +__all__ = [ "block_attach", "block_detach" ] + + +def get_state(domain, devname): + number = xen.util.blkif.blkdev_name_to_number(devname) + s, o = traceCommand("xm block-list %s | awk '/^%d/ {print $4}'" % + (domain.getName(), number)) + if s != 0: + FAIL("block-list failed") + if o == "": + return 0 + else: + return int(o) + + +def block_attach(domain, phy, virt): + status, output = traceCommand("xm block-attach %s %s %s w" % + (domain.getName(), phy, virt)) + if status != 0: + FAIL("xm block-attach returned invalid %i != 0" % status) + + for i in range(10): + if get_state(domain, virt) == 4: + break + time.sleep(1) + else: + FAIL("block-attach failed: device did not switch to Connected state") + + +def block_detach(domain, virt): + status, output = traceCommand("xm block-detach %s %s" % + (domain.getName(), virt)) + if status != 0: + FAIL("xm block-detach returned invalid %i != 0" % status) + + for i in range(10): + if get_state(domain, virt) == 0: + break + time.sleep(1) + else: + FAIL("block-detach failed: device did not disappear") diff --git a/tools/xm-test/tests/block-create/01_block_attach_device_pos.py b/tools/xm-test/tests/block-create/01_block_attach_device_pos.py index 492d83f2cf..13e6a5efb8 100644 --- a/tools/xm-test/tests/block-create/01_block_attach_device_pos.py +++ b/tools/xm-test/tests/block-create/01_block_attach_device_pos.py @@ -3,11 +3,10 @@ # Copyright (C) International Business Machines Corp., 2005 # Author: Murillo F. Bernardes -import sys import re -import time from XmTestLib import * +from XmTestLib.block_utils import * if ENABLE_HVM_SUPPORT: SKIP("Block-attach not supported for HVM domains") @@ -33,9 +32,7 @@ except ConsoleError, e: FAIL(str(e)) -status, output = traceCommand("xm block-attach %s phy:ram1 sdb1 w" % domain.getName()) -if status != 0: - FAIL("xm block-attach returned invalid %i != 0" % status) +block_attach(domain, "phy:ram1", "sdb1") try: run = console.runCmd("cat /proc/partitions") diff --git a/tools/xm-test/tests/block-create/02_block_attach_file_device_pos.py b/tools/xm-test/tests/block-create/02_block_attach_file_device_pos.py index df3f0d67a6..b4e7c6974a 100644 --- a/tools/xm-test/tests/block-create/02_block_attach_file_device_pos.py +++ b/tools/xm-test/tests/block-create/02_block_attach_file_device_pos.py @@ -3,11 +3,10 @@ # Copyright (C) International Business Machines Corp., 2005 # Author: Murillo F. Bernardes -import sys import re -import time from XmTestLib import * +from XmTestLib.block_utils import * if ENABLE_HVM_SUPPORT: SKIP("Block-attach not supported for HVM domains") @@ -33,9 +32,7 @@ except ConsoleError, e: FAIL(str(e)) -status, output = traceCommand("xm block-attach %s file:/dev/ram1 sdb2 w" % domain.getName()) -if status != 0: - FAIL("xm block-attach returned invalid %i != 0" % status) +block_attach(domain, "file:/dev/ram1", "sdb2") try: run = console.runCmd("cat /proc/partitions") diff --git a/tools/xm-test/tests/block-create/04_block_attach_device_repeatedly_pos.py b/tools/xm-test/tests/block-create/04_block_attach_device_repeatedly_pos.py index a3b9785785..6d9eb513fe 100644 --- a/tools/xm-test/tests/block-create/04_block_attach_device_repeatedly_pos.py +++ b/tools/xm-test/tests/block-create/04_block_attach_device_repeatedly_pos.py @@ -3,9 +3,7 @@ # Copyright (C) International Business Machines Corp., 2005 # Author: Murillo F. Bernardes -import sys import re -import time from XmTestLib import * diff --git a/tools/xm-test/tests/block-create/05_block_attach_and_dettach_device_repeatedly_pos.py b/tools/xm-test/tests/block-create/05_block_attach_and_dettach_device_repeatedly_pos.py index 7f7fe77ead..db406fecd4 100644 --- a/tools/xm-test/tests/block-create/05_block_attach_and_dettach_device_repeatedly_pos.py +++ b/tools/xm-test/tests/block-create/05_block_attach_and_dettach_device_repeatedly_pos.py @@ -3,11 +3,10 @@ # Copyright (C) International Business Machines Corp., 2005 # Author: Murillo F. Bernardes -import sys import re -import time from XmTestLib import * +from XmTestLib.block_utils import * if ENABLE_HVM_SUPPORT: SKIP("Block-attach not supported for HVM domains") @@ -33,18 +32,12 @@ except ConsoleError, e: for i in range(10): - status, output = traceCommand("xm block-attach %s phy:ram1 sdb1 w" % domain.getName()) - if status != 0: - FAIL("xm block-attach returned invalid %i != 0" % status) - # verify that it comes + block_attach(domain, "phy:ram1", "sdb1") run = console.runCmd("cat /proc/partitions") if not re.search("sdb1", run["output"]): FAIL("Failed to attach block device: /proc/partitions does not show that!") - status, output = traceCommand("xm block-detach %s 2065" % domain.getName()) - if status != 0: - FAIL("xm block-detach returned invalid %i != 0" % status) - # verify that it goes + block_detach(domain, "sdb1") run = console.runCmd("cat /proc/partitions") if re.search("sdb1", run["output"]): FAIL("Failed to dettach block device: /proc/partitions still showing that!") diff --git a/tools/xm-test/tests/block-create/07_block_attach_baddevice_neg.py b/tools/xm-test/tests/block-create/07_block_attach_baddevice_neg.py index 2c6b19e54a..f2043d7dd3 100644 --- a/tools/xm-test/tests/block-create/07_block_attach_baddevice_neg.py +++ b/tools/xm-test/tests/block-create/07_block_attach_baddevice_neg.py @@ -3,9 +3,7 @@ # Copyright (C) International Business Machines Corp., 2005 # Author: Murillo F. Bernardes -import sys import re -import time from XmTestLib import * diff --git a/tools/xm-test/tests/block-create/08_block_attach_bad_filedevice_neg.py b/tools/xm-test/tests/block-create/08_block_attach_bad_filedevice_neg.py index 8c129bd2a3..b1c776d71a 100644 --- a/tools/xm-test/tests/block-create/08_block_attach_bad_filedevice_neg.py +++ b/tools/xm-test/tests/block-create/08_block_attach_bad_filedevice_neg.py @@ -3,9 +3,7 @@ # Copyright (C) International Business Machines Corp., 2005 # Author: Murillo F. Bernardes -import sys import re -import time from XmTestLib import * diff --git a/tools/xm-test/tests/block-create/09_block_attach_and_dettach_device_check_data_pos.py b/tools/xm-test/tests/block-create/09_block_attach_and_dettach_device_check_data_pos.py index bcfb4fe26c..b997379a25 100644 --- a/tools/xm-test/tests/block-create/09_block_attach_and_dettach_device_check_data_pos.py +++ b/tools/xm-test/tests/block-create/09_block_attach_and_dettach_device_check_data_pos.py @@ -3,11 +3,10 @@ # Copyright (C) International Business Machines Corp., 2005 # Author: Murillo F. Bernardes -import sys import re -import time from XmTestLib import * +from XmTestLib.block_utils import * if ENABLE_HVM_SUPPORT: SKIP("Block-attach not supported for HVM domains") @@ -36,10 +35,7 @@ if s != 0: FAIL("mke2fs returned %i != 0" % s) for i in range(10): - status, output = traceCommand("xm block-attach %s phy:ram1 hda1 w" % domain.getName()) - if status != 0: - FAIL("xm block-attach returned invalid %i != 0" % status) - # verify that it comes + block_attach(domain, "phy:ram1", "hda1") run = console.runCmd("cat /proc/partitions") if not re.search("hda1", run["output"]): FAIL("Failed to attach block device: /proc/partitions does not show that!") @@ -56,10 +52,7 @@ for i in range(10): print run['output'] console.runCmd("umount /mnt/hda1") - status, output = traceCommand("xm block-detach %s 769" % domain.getName()) - if status != 0: - FAIL("xm block-detach returned invalid %i != 0" % status) - # verify that it goes + block_detach(domain, "hda1") run = console.runCmd("cat /proc/partitions") if re.search("hda1", run["output"]): FAIL("Failed to dettach block device: /proc/partitions still showing that!") diff --git a/tools/xm-test/tests/block-create/10_block_attach_dettach_multiple_devices.py b/tools/xm-test/tests/block-create/10_block_attach_dettach_multiple_devices.py index b538e3d936..833f75c21a 100644 --- a/tools/xm-test/tests/block-create/10_block_attach_dettach_multiple_devices.py +++ b/tools/xm-test/tests/block-create/10_block_attach_dettach_multiple_devices.py @@ -3,15 +3,14 @@ # Copyright (C) International Business Machines Corp., 2005 # Author: Murillo F. Bernardes -import sys import re -import time import random from xen.util import blkif from os import path.basename from XmTestLib import * +from XmTestLib.block_utils import * def availableRamdisks(): i = 0 @@ -21,11 +20,7 @@ def availableRamdisks(): return i def attach(phy, devname): - # Attach - status, output = traceCommand("xm block-attach %s phy:%s %s w" % (domain.getName(), phy, devname)) - if status != 0: - return -1, "xm block-attach returned invalid %i != 0" % status - + block_attach(domain, "phy:%s" % phy, devname) run = console.runCmd("cat /proc/partitions") if not re.search(basename(devname), run["output"]): return -2, "Failed to attach block device: /proc/partitions does not show that!" @@ -33,16 +28,12 @@ def attach(phy, devname): return 0, None -def dettach(devname): - devnum = blkif.blkdev_name_to_number(devname) - - status, output = traceCommand("xm block-detach %s %d" % (domain.getName(), devnum)) - if status != 0: - return -1, "xm block-attach returned invalid %i != 0" % status +def detach(devname): + block_detach(domain, devname) run = console.runCmd("cat /proc/partitions") if re.search(basename(devname), run["output"]): - return -2, "Failed to dettach block device: /proc/partitions still showing that!" + return -2, "Failed to detach block device: /proc/partitions still showing that!" return 0, None @@ -91,7 +82,7 @@ while i < ramdisks or devices: devname = random.choice(devices) devices.remove(devname) print "Detaching %s" % devname - status, msg = dettach(devname) + status, msg = detach(devname) if status: FAIL(msg) diff --git a/tools/xm-test/tests/block-destroy/01_block-destroy_btblock_pos.py b/tools/xm-test/tests/block-destroy/01_block-destroy_btblock_pos.py index 1e465b3c37..835dfa9b1d 100644 --- a/tools/xm-test/tests/block-destroy/01_block-destroy_btblock_pos.py +++ b/tools/xm-test/tests/block-destroy/01_block-destroy_btblock_pos.py @@ -4,6 +4,7 @@ # Author: Dan Smith from XmTestLib import * +from XmTestLib.block_utils import block_detach if ENABLE_HVM_SUPPORT: SKIP("Block-detach not supported for HVM domains") @@ -28,11 +29,7 @@ except ConsoleError, e: if run["return"] != 0: FAIL("block device isn't attached; can't detach!") -status, output = traceCommand("xm block-detach %s 769" % domain.getName(), - logOutput=True) -if status != 0: - FAIL("block-detach returned invalid %i != 0" % status) - +block_detach(domain, "hda1") try: run = console.runCmd("cat /proc/partitions | grep hda1") diff --git a/tools/xm-test/tests/block-destroy/02_block-destroy_rtblock_pos.py b/tools/xm-test/tests/block-destroy/02_block-destroy_rtblock_pos.py index 4055c7d887..47ff9a6fe5 100644 --- a/tools/xm-test/tests/block-destroy/02_block-destroy_rtblock_pos.py +++ b/tools/xm-test/tests/block-destroy/02_block-destroy_rtblock_pos.py @@ -4,6 +4,7 @@ # Author: Dan Smith from XmTestLib import * +from XmTestLib.block_utils import * if ENABLE_HVM_SUPPORT: SKIP("Block-detach not supported for HVM domains") @@ -17,11 +18,7 @@ except DomainError, e: print e.extra FAIL("Unable to create domain") -status, output = traceCommand("xm block-attach %s phy:/dev/ram0 hda1 w" % domain.getName()) -if status != 0: - FAIL("Failed to attach block device") - pass - +block_attach(domain, "phy:/dev/ram0", "hda1") try: run = console.runCmd("cat /proc/partitions | grep hda1") except ConsoleError, e: @@ -31,10 +28,7 @@ except ConsoleError, e: if run["return"] != 0: FAIL("Failed to verify that block dev is attached") -status, output = traceCommand("xm block-detach %s 769" % domain.getName()) -if status != 0: - FAIL("block-detach returned invalid %i != 0" % status) - +block_detach(domain, "hda1") try: run = console.runCmd("cat /proc/partitions | grep hda1") except ConsoleError, e: diff --git a/tools/xm-test/tests/block-destroy/05_block-destroy_byname_pos.py b/tools/xm-test/tests/block-destroy/05_block-destroy_byname_pos.py index 3f43fe9d95..d77e587c33 100644 --- a/tools/xm-test/tests/block-destroy/05_block-destroy_byname_pos.py +++ b/tools/xm-test/tests/block-destroy/05_block-destroy_byname_pos.py @@ -4,6 +4,7 @@ # Author: Dan Smith from XmTestLib import * +from XmTestLib.block_utils import block_detach if ENABLE_HVM_SUPPORT: SKIP("Block-detach not supported for HVM domains") @@ -27,11 +28,7 @@ except ConsoleError, e: if run["return"] != 0: FAIL("block device isn't attached; can't detach!") -status, output = traceCommand("xm block-detach %s hda1" % domain.getName(), - logOutput=True) -if status != 0: - FAIL("block-detach returned invalid %i != 0" % status) - +block_detach(domain, "hda1") try: run = console.runCmd("cat /proc/partitions | grep hda1") diff --git a/tools/xm-test/tests/block-destroy/06_block-destroy_check_list_pos.py b/tools/xm-test/tests/block-destroy/06_block-destroy_check_list_pos.py index 25bba2183c..38d60a92c1 100644 --- a/tools/xm-test/tests/block-destroy/06_block-destroy_check_list_pos.py +++ b/tools/xm-test/tests/block-destroy/06_block-destroy_check_list_pos.py @@ -4,19 +4,10 @@ # Author: Dan Smith from XmTestLib import * +from XmTestLib.block_utils import * -import time import re -def checkBlockList(domain): - s, o = traceCommand("xm block-list %s" % domain.getName()) - if s != 0: - FAIL("block-list failed") - if re.search("769", o): - return True - else: - return False - def checkXmLongList(domain): s, o = traceCommand("xm list --long %s" % domain.getName()) if s != 0: @@ -26,12 +17,6 @@ def checkXmLongList(domain): else: return False -def checkBlockState(domain): - s, o = traceCommand("xm block-list %s | awk '{print $4}' |tail -n 1" % domain.getName()) - if s != 0: - FAIL("block-list failed") - return int(o) - if ENABLE_HVM_SUPPORT: SKIP("Block-detach not supported for HVM domains") @@ -42,32 +27,12 @@ try: except DomainError,e: FAIL(str(e)) -s, o = traceCommand("xm block-attach %s phy:/dev/ram0 hda1 w" % domain.getName()) -if s != 0: - FAIL("block-attach failed") - -if not checkBlockList(domain): - FAIL("block-list does not show that hda1 was attached") +block_attach(domain, "phy:/dev/ram0", "hda1") if not checkXmLongList(domain): FAIL("xm long list does not show that hda1 was attached") -for i in range(1, 10): - time.sleep(1) - state = checkBlockState(domain) - if state == 4: - break - -s, o = traceCommand("xm block-detach %s hda1" % domain.getName()) -if s != 0: - FAIL("block-detach failed") - -time.sleep(2) - -if checkBlockList(domain): - FAIL("block-list does not show that hda1 was removed") +block_detach(domain, "hda1") if checkXmLongList(domain): FAIL("xm long list does not show that hda1 was removed") - - diff --git a/tools/xm-test/tests/block-list/02_block-list_attachbd_pos.py b/tools/xm-test/tests/block-list/02_block-list_attachbd_pos.py index c189dbe335..256b44d951 100644 --- a/tools/xm-test/tests/block-list/02_block-list_attachbd_pos.py +++ b/tools/xm-test/tests/block-list/02_block-list_attachbd_pos.py @@ -1,5 +1,5 @@ #!/usr/bin/python - + # Copyright (C) International Business Machines Corp., 2005 # Author: Li Ge from XmTestLib import * +from XmTestLib.block_utils import * if ENABLE_HVM_SUPPORT: SKIP("Block-list not supported for HVM domains") @@ -21,9 +22,7 @@ if s != 0: if o: FAIL("block-list without devices reported something!") -s, o = traceCommand("xm block-attach %s phy:/dev/ram0 hda1 w" % domain.getName()) -if s != 0: - FAIL("Unable to attach /dev/ram0->hda1") +block_attach(domain, "phy:/dev/ram0", "hda1") s, o = traceCommand("xm block-list %s" % domain.getName()) if s != 0: @@ -31,9 +30,7 @@ if s != 0: if o.find("769") == -1: FAIL("block-list didn't show the block device I just attached!") -s, o = traceCommand("xm block-attach %s phy:/dev/ram1 hda2 w" % domain.getName()) -if s != 0: - FAIL("Unable to attach /dev/ram1->hda2") +block_attach(domain, "phy:/dev/ram1", "hda2") s, o = traceCommand("xm block-list %s" % domain.getName()) if s != 0: @@ -41,11 +38,8 @@ if s != 0: if o.find("770") == -1: FAIL("block-list didn't show the other block device I just attached!") -s, o = traceCommand("xm block-detach %s 769" % domain.getName()) -if s != 0: - FAIL("block-detach of hda1 failed") +block_detach(domain, "hda1") -time.sleep(1) s, o = traceCommand("xm block-list %s" % domain.getName()) if s != 0: FAIL("block-list failed after detaching a device") @@ -54,11 +48,8 @@ if o.find("769") != -1: if o.find("770") == -1: FAIL("hda2 not shown after detach of hda1!") -s, o = traceCommand("xm block-detach %s 770" % domain.getName()) -if s != 0: - FAIL("block-detach of hda2 failed") +block_detach(domain, "hda2") -time.sleep(1) s, o = traceCommand("xm block-list %s" % domain.getName()) if s != 0: FAIL("block-list failed after detaching another device")